import { sendReportRender, type RenderRequest } from '@/services/report';
import { useState } from 'react';

export function useReport() {
  const [rendering, setRendering] = useState<boolean>(false);

  const render = async ({ convertTo, data }: RenderRequest) => {
    try {
      setRendering(true);
      console.log('设置为 true');

      const renderRes = await sendReportRender({ convertTo, data });
      console.log(renderRes);
      return renderRes;
    } catch (error) {
      console.error(error);
      throw error;
    } finally {
      console.log('设置为 false');
      setRendering(false);
    }
  };

  return {
    render,
    rendering,
  };
}
